package com.luocj.looook.adapter;

import android.support.v4.app.FragmentActivity;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.luocj.looook.R;
import com.luocj.looook.model.MultipeItemL;

import java.util.List;

/**
 * Created by luocj515 on 2017/12/5.
 * 项目名称：LooooK
 * 类描述：
 * 创建人：hasee
 * 创建时间：2017/12/5 23:52
 * 修改备注：
 */

public class MultipleItemLAdapter extends BaseMultiItemQuickAdapter<MultipeItemL, BaseViewHolder> {
    private int[] images = new int[]{R.mipmap.b1, R.mipmap.b2, R.mipmap.b3};

    public MultipleItemLAdapter(FragmentActivity activity, List<MultipeItemL> data) {
        super(data);
        init();
    }

    private void init() {

        addItemType(MultipeItemL.TEXT, R.layout.item_type_one);
        addItemType(MultipeItemL.IMAGE, R.layout.item_type_two);
        addItemType(MultipeItemL.TEXT_IMAGE, R.layout.item_type_three);
    }

    @Override
    protected void convert(BaseViewHolder holder, MultipeItemL item) {
        switch (holder.getItemViewType()) {
            case MultipeItemL.TEXT:
                holder.setText(R.id.tv_item_one, "itemSpanSize :-->" + item.getSpanSize());
                break;

            case MultipeItemL.IMAGE:
                holder.setImageResource(R.id.iv_item_two, images[holder.getLayoutPosition() % 3]);
                break;
            case MultipeItemL.TEXT_IMAGE:
                holder.setText(R.id.tv_item_three, "position ：" + holder.getLayoutPosition());
                holder.setImageResource(R.id.iv_item_three, images[(int) (Math.random() * 3)]);
                break;
            default:
                break;
        }
    }
}
